﻿using Nature.Core.Config;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Nature.Core.Cache
{
    public class ConfigCacheGroup : BaseConfigElement
    {
        /// <summary>
        ///     由哪个类提供了对这个缓存的实现
        ///     这里需要数据该类的全称
        /// </summary>
        [ConfigurationProperty("provider", DefaultValue = "Nature.Core.Cache.DefaultCacheStrategy")]
        public virtual string Provider
        {
            get { return (string)base["provider"]; }
            set { base["provider"] = value; }
        }

        /// <summary>
        ///     将Provider转换成了对应的Type对象
        ///     如果配置信息错了，这里会因无法转换成Type对象而抛出异常
        /// </summary>
        public virtual Type Type
        {
            get { return Type.GetType(Provider); }
        }

        /// <summary>
        ///     缓存的默认时间
        ///     格式：HH:mm:ss
        /// </summary>
        [ConfigurationProperty("interval", DefaultValue = "00:10:00")]
        public virtual TimeSpan Interval
        {
            get { return (TimeSpan)base["interval"]; }
            set { base["interval"] = value; }
        }

        /// <summary>
        ///     备注，框架内并未使用该字段
        /// </summary>
        [ConfigurationProperty("notes", IsRequired = false)]
        public virtual string Notes
        {
            get { return (string)base["notes"]; }
            set { base["notes"] = value; }
        }
    }
}
